class TrendController < ApplicationController
  def all
    tables = ["novels", "fragments", "comments", "votes", "merge_histories"]
    #@trends = Novel.find_by_sql "select n.id as novelid,f.id as fragmentid,c.id as commentid,v.id as voteid,m.id as mergehistoryid from"
    sql="select "
    fields = ""
    from = "from "
    tables.each do |table|
      table_alias=table[0, 1]
      fields << table_alias <<"\.id as "<< "#{table}_id"
      fields << ","
      from << table<<" as #{table_alias}"
      from << ","
    end
    sql << fields[0, fields.size-1] << " "<<from[0, from.size-1] << "  limit 30"
    puts sql
    @trends=Novel.find_by_sql sql
  end
end
